<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
    <script type="text/javascript" src="${ctx}/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/ShopRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/MarketRpcService.js'></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<form>
	<center>
		<table style="width: 50%;" cellpadding="5" cellspacing="5">
            <tr>
			    <td>
			        <select id="marketId" name="marketId" onchange="getShopPage()">
			        </select>
			    </td>
			    <td>
			        <button type="button" onclick="submitShop('')">添加车商</button>
			    </td>
			</tr>
        </table>
    </center>
</form>

<SCRIPT LANGUAGE="JavaScript" >
    var shopThead = new Array(
            new XThead("店铺名称"),
            new XThead("市场名称"),
            new XThead("联系电话"),
            new XThead("店铺地址"),
            new XThead("负责人信息"),
            new XThead("店铺状态"),
        	new XThead("在售车辆"),
            new XThead("操作")
    );

    var shopXTable = new XTable("shop", shopThead);

    shopXTable.XTbodyArray = function (model) {
        var array = new Array(
                new XTbody("shop", model.shopName, "string", null, null, "center"),
                new XTbody("shop", model.market.marketName, "string", null, null, "center"),
                new XTbody("shop", model.shopMobile, "string", null, null, "center"),
                new XTbody("shop", model.shopAddress, "string", null, null, "center"),
                new XTbody("shop", "负责人姓名：" + model.shopManageName + "<br>" + "联系方式：" + model.shopManageMobile, "string", null, null, "center"),
            	new XTbody("shop", model.shopState == 0 ? '已冻结':'正常', "string", null, null, "center"),
			    new XTbody("shop", "<a href='#' onclick=redirectToCar('"+ model.shopId +"')>"+model.carNum+"</a>", "string", null, null, "center"),
                new XTbody("shop", "<a href='#' style='border-right: 1px solid #dddddd' onclick=submitShop('"+ model.shopId +"')>编辑&nbsp;</a>" + "<a href='#' onclick=showContractList('"+ model.shopId +"')>&nbsp;租赁信息</a>", "string", null, null, "center")
        );
        return array;
    }

    shopXTable.getXList = function (page){
        var shop = new Shop();
        shop.marketId = dwr.util.getValue("marketId");
        shop.pageIndex = page;
        shop.pageSize = shopXTable.pageSize;
        ShopRpcService.selectShopList(shop, function(list){shopXTable.addTable(list);});
    }

    function getShopPage(){
        var shop = new Shop();
        shop.marketId = dwr.util.getValue("marketId");
        ShopRpcService.selectShopNum(shop, function(num){shopXTable.setTotalPage(num);}) ;
    }
</SCRIPT>
</body>
</html>
<script>
    var market = new Market();
    market.marketId = "${marketId}";
    MarketRpcService.selectMarketList(market, callbackSelectMarketList);

    function callbackSelectMarketList(list) {
        dwr.util.addOptions("marketId", list, "marketId", "marketName");
        dwr.util.setValue("marketId", "${marketId}");
        getShopPage();
    }

    function submitShop(shopId){
        location = "${ctx}/shop/shop_manage.jsp?shopId=" + shopId;
    }
    
    function dongJie(shopId){
    	if (shopId == null || shopId == '') {
            return false;
        }
    	
    	if(confirm('确定要冻结吗？')){
    		var shop = new Shop();
    		shop.shopId = shopId;
    		shop.shopState = 0;
    		ShopRpcService.updateShop(shop, callbackUpdateShop);
    	}else{
    		return;
    	}
    }
    
    function callbackUpdateShop(data){
    	if(data){
    		alert('冻结成功!');
    		location.reload();
    	}
    }
    
    function jieDong(shopId){
    	if (shopId == null || shopId == '') {
            return false;
        }
    	
    	if(confirm('确定要解冻吗？')){
    		var shop = new Shop();
    		shop.shopId = shopId;
    		shop.shopState = 1;
    		ShopRpcService.updateShop(shop, callbackUpdateShopJD);
    	}else{
    		return;
    	}
    }

    function showContractList(shopId){
        location = "${ctx}/contract/contract_list.jsp?detail=1&shopId=" + shopId;
	}

    function callbackUpdateShopJD(data){
    	if(data){
    		alert('解冻成功!');
    		location.reload();
    	}
    }
    function redirectToCar(shopId){
        window.open("${ctx}/cars/src/list_shop.html?shopId="+shopId);
	}
</script>
